package com.edu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.edu.entity.Course;
import com.edu.entity.Teacher;
import com.edu.service.CourseService;
import com.edu.service.TeacherService;
import com.edu.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 麦翔盛
 * @description: 讲师前台界面控制类
 * @date 2021/11/14 19:54
 */
@CrossOrigin
@RequestMapping("/edu/font/teacher")
@RestController
public class TeacherFontController {
    @Autowired
    private TeacherService teacherService;

    @Autowired
    private CourseService courseService;

    /**
     * 前台展示讲师界面
     * @return
     */
    @PostMapping("/list/{page}/{limit}")
    public R listTeacherFont(@PathVariable long page, @PathVariable long limit){
        Page<Teacher> teacherPage = new Page<>(page,limit);
        HashMap<String,Object> map  = teacherService.getTeacherFontList(teacherPage);
        return R.success().data(map);
    }

    /**
     * 根据教师id返回教师信息
     * @param teacherId
     * @return
     */
    @GetMapping("/getTeacherFontInfo/{teacherId}")
    public R getTeacherFontInfo(@PathVariable String teacherId){
        //获取该讲师的所有课程
        QueryWrapper<Course> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("teacher_id",teacherId);
        List<Course> courseList = courseService.list(queryWrapper);
        //查询老师的信息
        Teacher teacher = teacherService.getById(teacherId);
        return R.success().data("teacher",teacher).data("courseList",courseList);
    }
}
